﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Douban.Core
{
    public abstract class ObservableObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(string propName)
        {
            VerifyProperty(propName);

            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }

        private void VerifyProperty(string propName)
        {
            if(TypeDescriptor.GetProperties(this)[propName] == null)
                throw new ArgumentException("Unknown property: " + propName);
        }
    }
}
